<?php
defined('BASEPATH') OR exit('No direct script access allowed');

 use QCloud_WeApp_SDK\Auth\LoginService as LoginService;
// use QCloud_WeApp_SDK\Constants as Constants;
// use QCloud_WeApp_SDK\Mysql\Mysql as DB;

use QCloud_WeApp_SDK\Mysql\Mysql as DB;
class SoboDb extends CI_Controller {
public function index()
	{
		$postda = $this->input->post('name');
		$postadr= $this->input->post('address');
		$poststar=$this->input->post('starr');
		//echo $poststar;		
		echo $postadr;

	}





// 检查登录用户是否有授权登录记录
// 
public function getpatinfo()
{
     $postoppenid = $this->input->get('oppenid'); 

     if ($postoppenid != null) {            
          $fromid = db::select('userinfo',['*'],'oppenid ="'.$postoppenid.'"');         
          echo json_encode($fromid);

     } else {
          echo "错误，未接收到请求关键字 ！";     }
     
}




//注册用户插入
public function inser()
{
          $postsex = $this->input->post('sex');
          if ($postsex=='男') {
          	$sex=1;
          } else {
          	$sex=0 ;
          }
       
          $postadr = $this->input->post('address');
          $postbir = $this->input->post('birthday');
          $postpn = $this->input->post('phoneNum');
          $postop = $this->input->post('oppenid');
          $postnname = $this->input->post('nicname');
          $postda = array(
          	'sex' => $sex,
          	'address' => $postadr,
          	'birthday' => $postbir,
          	'phonename' => $postpn,
          	'oppenid' => $postop,
          	'nicname' => $postnname
          	);
          //echo $postop;

	$inser=db::insert('userinfo',$postda);
     
     // 如果插入信息没错，返回1，继续查询到新登记信息的ID，以便下一步登记新患者信息
     if ($inser == 1) {
          // 插入信息没错，开始获取新登记信息的ID
          $record = db::select('userinfo',['*'],'oppenid="'.$postop.'"');
         // 判断如果查询得到的记录是一条，就开始插入到患者数据库登记用户信息 
          $core=json_encode($record);
           echo $core;
         
           //      // 患者信息数据创建完毕


     } else {
         echo "错误，登记信息错误";
     }

}





  // 插入新登录用户至患者信息表
    // 获取提交新患者信息
  public function inserpat()
   {
     // '获取提交新患者信息'
  
          $name = $this->input->post('pat_name');
          $relation = $this->input->post('relation');
          $birthday = $this->input->post('birthday');
          $sex = $this->input->post('sex');
          $from_id = $this->input->post('from_id');
          $from_op = $this->input->post('from_op');
          $address = $this->input->post('address');
          if ($sex == '男' || $sex == 1 ) {
           $sex=1; 
          } else {
           $sex=0;
          }
          

          $postda = array(
                      'pat_name' => $name,
                      'relation' => $relation,
                      'birthday' => $birthday,
                      'sex' => $sex,
                      'from_id' => $from_id,
                      'from_op' => $from_op,
                      'address' => $address

                      );
              $patinser=db::insert('patient',$postda);
              echo $patinser;
   } 
  


               //      




// 获取用户咨询患者记录
public function getpatlist()
{
     $postoppenid = $this->input->get('oppenid');
     $postid = $this->input->get('userid');
     if ($postoppenid != null) {    
          $record=db::select('patient',['*'],'from_op="'.$postoppenid.'" OR from_id="'.$postid.'"');
          echo json_encode($record);

     } else {
          echo "错误，未接收到请求关键字 ！";     }
     
}








}
